{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#python为了将语义变得更加明确，就引入了async和await关键词用于定义原生的协程\n",
    "# async def downloader(url):\n",
    "#     return \"bobby\"\n",
    "import types\n",
    "\n",
    "@types.coroutine\n",
    "def downloader(url):\n",
    "    yield \"bobby\"\n",
    "\n",
    "async def download_url(url):\n",
    "    #dosomethings\n",
    "    ## await 后面添加锕 waitable 对象\n",
    "    ## 普通函数需要添加 @type.coroutine 装饰器\n",
    "    html = await downloader(url)\n",
    "    return html\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    coro = download_url(\"http://www.imooc.com\")\n",
    "    # next(None)\n",
    "    coro.send(None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
